//
//  TableScrollCell.m
//  轮胎商城
//
//  Created by 张晋磊 on 2017/3/24.
//  Copyright © 2017年 张晋磊. All rights reserved.
//

#import "TableScrollCell.h"

@interface TableScrollCell ()

@property (nonatomic,copy) MwyBlock block;

@end

@implementation TableScrollCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
    
        [self.contentView addSubview:self.scrl];
    }
    return self;
}



-(void)setArr:(NSArray *)arr{

    _arr = arr;
    
    _scrl.contentSize = CGSizeMake(arr.count * _scrl.frame.size.width, _scrl.frame.size.height);
    
    for(int i=0;i<arr.count;i++){
        
        UIButton *bt = [[UIButton alloc]initWithFrame:CGRectMake(i * _scrl.frame.size.width, 0, _scrl.frame.size.width, _scrl.frame.size.height)];
        
        [bt setImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
        bt.tag = 100+i;
        [bt addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        bt.imageView.contentMode = UIViewContentModeScaleToFill;
        
        [_scrl addSubview:bt];
    }

}



-(void)buttonClick:(UIButton *)bt{

    if(_block){
    
        NSLog(@"点击了图片%@",_block(bt.tag));
    }
}

-(void)coputeButtonClick:(NSString *(^)(NSInteger))block{

    if(_block != block){
    
        _block = block;
    }
}



-(UIScrollView *)scrl{

    if(!_scrl){
    
        CGSize size = [UIScreen mainScreen].bounds.size;
        _scrl = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, size.width, 120)];
        _scrl.pagingEnabled = YES;
  
    }
    return _scrl;
}


@end
